package com.example.administrator.myapplication.View.Adapter;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.view.ViewGroup;

import java.util.ArrayList;
import java.util.List;
/**
 * Created by Administrator on 2019/6/13 0013.
 */

public class MyFragmentAdapter extends FragmentPagerAdapter {
    private  List<Fragment> fragments = new ArrayList<Fragment>();
    private  List<String> fragmentsTitles = new ArrayList<>();
    public MyFragmentAdapter(FragmentManager fm, List<Fragment> fragments) {
        super(fm);
        this.fragments = fragments;
    }
    public MyFragmentAdapter(FragmentManager fm, List<Fragment> fragments,List<String> fragmenttitles) {
        super(fm);
        this.fragments = fragments;
        this.fragmentsTitles = fragmenttitles;
    }

    @Override
    public Fragment getItem(int position) {
        return fragments.get(position);
    }

    @Override
    public int getCount() {
        return fragments.size();
    }
    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        super.destroyItem(container, position, object);
    }

    @Override
    public CharSequence getPageTitle(int position) {
        if(fragmentsTitles!=null)
            return fragmentsTitles.get(position);
        else
            return "Fault";
    }
}
